<?
require_once("mvc/action/Action.php");
require_once("cms/staff/om/StaffPeer.php");

class EditAction extends Action {

    private $log;

    public function __construct() {
        $this->log =& LoggerManager::getLogger("EditAction");
    }

    public function execute(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        if($form->getStaff()->getStaffId() > 0) {
            $staff = StaffPeer::retrieveByPk($form->getStaff()->getStaffId());
            if(!is_null($staff)) {

                // Hide the password. Is one-way encrypted so not usable.
                $staff->setPassword("");
                $form->setStaff($staff);

                // Get the staffroles
                $roles = array();
                foreach($staff->getStaffRoles() as $staffRole) {
                    $roles[] = $staffRole->getRolename();
                }
                $form->setRoles($roles);

            } else {
                $this->log->error("No staff found with id {$form->getStaff()->getStaffId()}.");
                $form->getStaff()->setStaffId("");
            }
        }

        return $mapping->findForward("success");

    }

}
?>